package sample.plugin.di;

import com.qiplat.open.ui.widget.dialog.QiBottomDialog;
import com.rapid.api.Unit;
import com.rapid.api.ext.framework.BaseObject;
import com.rapid.api.framework.domain.window.WindowService;
import com.rapid.api.framework.project.primary.ProjectLifecycleEvent;
import com.rapid.api.project.Project;
import com.rapid.api.project.ProjectManager;
import com.rapid.api.project.service.LanguageManager;
import com.rapid.framework.annotation.SourceUnit;

/**
 * 这是个随意写的类
 * 该类演示使用构造注入
 */
public class ConstructorInject extends BaseObject implements ProjectLifecycleEvent {
    private WindowService windowService;
    private LanguageManager languageManager;

    /**
     * 通过构造注入依赖的对象
     * 其中SourceUnit注解用于指定数据单元，不指定默认从全局作用域装配
     */
    public ConstructorInject(
            WindowService windowService,
            @SourceUnit(unitId = Unit.Ids.PROJECT, identifier = "std.android") LanguageManager languageManager
    ) {
        this.windowService = windowService;
        this.languageManager = languageManager;
    }

    @Override
    public void beforeLoadingProject(Project project, ProjectManager<?> projectManager) {

    }

    @Override
    public void afterLoadingProject(Project project, ProjectManager<?> projectManager) {
        runUI(() -> {
            String message = "成功装配：\n";
            message += windowService + "\n\n";
            message += languageManager;
            QiBottomDialog.show(
                    getActivity(),
                    getClass().getSimpleName(),
                    message
            );
        });
    }

    @Override
    public void onCloseProject(Project project, ProjectManager<?> projectManager) {

    }
}
